import ComponentConfiguration from "@site/src/pages/components-explorer/_components/ComponentConfiguration";
import ComponentHeader from "@site/src/pages/components-explorer/_components/ComponentHeader";
import ComponentTroubleshooting from "@site/src/pages/components-explorer/_components/ComponentTroubleshooting/index.mdx";

import ComponentMetadata from "./_meta";
import config from "./config.json";

<ComponentHeader meta={ComponentMetadata} />

The Gotify component allows Viseron to send notifications to a [Gotify](https://gotify.net/) server when recordings start. Gotify is a simple server for sending and receiving push notifications. It's self-hosted, open-source, and provides a simple way to send notifications to your devices.

## Features

- Send notifications to Gotify when recordings start
- Include thumbnails of detected objects in notifications (when enabled)
- Configure notification priority
- Filter notifications by object type
- Only send notifications for objects that trigger recordings

## How It Works

The Gotify component listens for the `EVENT_RECORDER_START` event, which is triggered when a recording starts. When this event occurs, the component:

1. Checks if the recording contains objects
2. Filters objects based on the configured detection labels
3. Sends a notification to the Gotify server with:
   - A text message
   - A thumbnail image (if `send_thumbnail` is enabled and a thumbnail is available)

## Installation

1. Set up a Gotify server if you don't already have one. You can follow the [official documentation](https://gotify.net/docs/install).
2. Create an application in Gotify and get the application token.
3. Configure the Gotify component in your Viseron configuration file.

## Configuration

<details>
  <summary>Configuration example</summary>

```yaml title="/config/config.yaml"
gotify:
  gotify_url: "https://gotify.example.com" # URL to your Gotify server
  gotify_token: "YOUR_APPLICATION_TOKEN" # Application token from Gotify
  priority: 5 # Priority of the notifications (1-10)
  detection_label: "person,cat" # Labels of objects to send notifications for
  send_thumbnail: true # Send a thumbnail of the detected object
  use_public_url: true # Generate a temp public URL with a unique token for the image. Require public_base_url in webserver conf
  image_max_size: 800 # Maximum width/height in pixels for thumbnails (default: 800). For 4K cameras, use 1920 or higher
  image_quality: 95 # JPEG quality for images (1-100, default: 95). Higher = better quality but larger files
  cameras:
    camera1: # Camera identifier with empty config
    camera2: # Another camera identifier
      detection_label: "car,truck" # Override detection labels for this camera
      send_thumbnail: false # Override thumbnail setting for this camera
```

</details>

<ComponentConfiguration meta={ComponentMetadata} config={config} />

## Limitations

- Gotify doesn't support direct video uploads, so the component only sends a notification that a video was recorded
- Image thumbnails are sent as base64-encoded images in markdown format, which requires a Gotify client that supports this format

<ComponentTroubleshooting meta={ComponentMetadata} />

### Common Issues

- **No notifications are being sent**: Ensure your Gotify server is accessible from the device running Viseron
- **Authentication errors**: Check that the application token has the correct permissions
- **Connection issues**: Verify that the URL is correct and includes the protocol (http:// or https://)
- **Missing thumbnails**: Make sure the `send_thumbnail` option is enabled and that the recording contains a thumbnail
